package com.spartez.farhorizons.server.dao;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.users.User;
import com.spartez.farhorizons.client.data.ISystemDescr;
import com.spartez.farhorizons.client.data.SystemDescr;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class PlayerData {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Long id;
    
    @Persistent
    private User owner;
    
    @Persistent
    private Collection<SystemDescription> systemDescrs;
    
    public PlayerData(User owner) {
    	this.owner = owner;
    	systemDescrs = Collections.emptySet();
    }

	public User getOwner() {
		return owner;
	}

	public void setOwner(User owner) {
		this.owner = owner;
	}

	public Set<ISystemDescr> getSystemDescrs() {
		final Set<ISystemDescr> result = new HashSet<ISystemDescr>(systemDescrs.size());
		for (ISystemDescr sysDescr : systemDescrs) {
			result.add(new SystemDescr(sysDescr));
		}
		return result;
	}

	public void setSystemDescrs(Collection<? extends ISystemDescr> systemDescrs) {
		this.systemDescrs = new ArrayList<SystemDescription> (systemDescrs.size());
		for (ISystemDescr sysDescr : systemDescrs) {
			this.systemDescrs.add(new SystemDescription(sysDescr));
		}
	}

	public Long getId() {
		return id;
	}
    
    
}
